const isDev = true,
  devBaseUrl = '',
  prodBaseUrl = '';
let baseUrl
baseUrl = !isDev ? devBaseUrl : prodBaseUrl;

// 网络请求
const wxRequest = (params, flag = false) => {
  try {
    const token = wx.getStorageSync('token');
    return new Promise((resolve, reject) => {
      if (!flag) wx.showLoading({
        title: '加载中',
        mask: true
      });
      wx.request({
        ...params,
        url: baseUrl + params.url,
        timeout: 15000,
        header: {
          token: token
        },
        success: (res) => {
          resolve(res.data);
        },
        fail: (err) => {
          reject(err);
        },
        complete: () => {
          if (!flag) wx.hideLoading();
        },
      });
    });
  } catch (e) {
    return new Promise((resolve, reject) => {
      wx.showLoading({
        title: '加载中',
        mask: true,
      });
      wx.request({
        ...params,
        url: baseUrl + params.url,
        timeout: 15000,
        header: {
          token: '',
        },
        success: (res) => {
          resolve(res.data);
        },
        fail: (err) => {
          reject(err);
        },
        complete: () => {
          wx.hideLoading();
        },
      });
    });
  }
};

export {
  wxRequest,
  baseUrl
};